home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GameStar 2005 March
/
Gamestar_71_2005-03_dvd.iso
/
Dema
/
willofsteel_demo.exe
/
{app}
/
Data
/
Shaders
/
MultiAnimation00.fx
< prev
next >
Wrap
Text File
|
2004-10-23
|
5KB
|
187 lines
float4x4 WorldViewProjection;
float4x4 ShadowViewProjection;
float4x4 TextureMatrix;
float4x4 WorldMatrix;
float4x4 ViewIT;
texture DiffuseTexture;
texture ShadowTexture;
texture CloudsTexture;
float4 SunColor = { 1., 0.86, .70, .0 };
float4 Ambient = { 0.3058, 0.1827, .10, 1.0 };
float3 LightDirection = { 0.7, 0.7, 0.0 };
float4 ZBias = { 0.0, 0.0, 0.0, -0.003 };
float3 UpVector = { 0.0, 1.0, 0.0 };
float4 Zero = { .0, .0, .0, .0 };
float4 Selected = { .0, 1., .0, 1. };
float4 CloudUVShift = { 0.0, 0.0, 0.0, 0.0 };
float4 CloudScale = { 0.01, 0.01, 0.01, 0.01 };
#ifndef MATRIX_PALETTE_SIZE_DEFAULT
#define MATRIX_PALETTE_SIZE_DEFAULT 23
#endif
const int MATRIX_PALETTE_SIZE = MATRIX_PALETTE_SIZE_DEFAULT;
float4x3 amPalette[ MATRIX_PALETTE_SIZE_DEFAULT ];
//----------------------------------------------------------------------------
// Shader body - VS_ Skin
//----------------------------------------------------------------------------
// define the inputs -- caller must fill this, usually right from the VB
struct VS_SKIN_INPUT
{
float4 vPos;
float3 vBlendWeights;
float4 vBlendIndices;
float3 vNor;
};
// return skinned position and normal
struct VS_SKIN_OUTPUT
{
float4 vPos;
float3 vNor;
};
// call this function to skin VB position and normal
VS_SKIN_OUTPUT VS_Skin( const VS_SKIN_INPUT vInput, int iNumBones )
{
VS_SKIN_OUTPUT vOutput = (VS_SKIN_OUTPUT) 0;
float fLastWeight = 1.0;
float fWeight;
float afBlendWeights[ 3 ] = (float[ 3 ]) vInput.vBlendWeights;
int aiIndices[ 4 ] = (int[ 4 ]) D3DCOLORtoUBYTE4( vInput.vBlendIndices );
for( int iBone = 0; (iBone < 3) && (iBone < iNumBones - 1); ++ iBone )
{
fWeight = afBlendWeights[ iBone ];
fLastWeight -= fWeight;
vOutput.vPos.xyz += mul( vInput.vPos, amPalette[ aiIndices[ iBone ] ] ) * fWeight;
vOutput.vNor += mul( vInput.vNor, amPalette[ aiIndices[ iBone ] ] ) * fWeight;
}
vOutput.vPos.xyz += mul( vInput.vPos, amPalette[ aiIndices[ iNumBones - 1 ] ] ) * fLastWeight;
vOutput.vNor += mul( vInput.vNor, amPalette[ aiIndices[ iNumBones - 1 ] ] ) * fLastWeight;
return vOutput;
}
float4 lhtDir = { 0.0f, 0.0f, -1.0f, 1.0f }; // light Direction
float4 lightDiffuse = { 0.6f, 0.6f, 0.6f, 1.0f }; // Light Diffuse
float4 MaterialAmbient : MATERIALAMBIENT = { 0.1f, 0.1f, 0.1f, 1.0f };
float4 MaterialDiffuse : MATERIALDIFFUSE = { 0.8f, 0.8f, 0.8f, 1.0f };
float4x4 mViewProj : VIEWPROJECTION;
///////////////////////////////////////////////////////
struct VS_INPUT
{
float4 Pos : POSITION;
float3 BlendWeights : BLENDWEIGHT;
float4 BlendIndices : BLENDINDICES;
float3 Normal : NORMAL;
float3 Tex0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 Pos : POSITION;
float4 Diffuse : COLOR;
float2 Tex0 : TEXCOORD0;
};
float3 Diffuse( float3 Normal )
{
float CosTheta;
// N.L Clamped
CosTheta = max( 0.0f, dot( Normal, lhtDir.xyz ) );
// propogate scalar result to vector
return ( CosTheta );
}
VS_OUTPUT VShade( VS_INPUT i, uniform int iNumBones )
{
VS_OUTPUT o;
float3 Pos = 0.0f;
float3 Normal = 0.0f;
float LastWeight = 0.0f;
// skin VB inputs
VS_SKIN_INPUT vsi = { i.Pos, i.BlendWeights, i.BlendIndices, i.Normal };
VS_SKIN_OUTPUT vso = VS_Skin( vsi, iNumBones );
// transform position from world space into view and then projection space
o.Pos = mul( float4( vso.vPos.xyz, 1.0f ), mViewProj );
// normalize normals
Normal = normalize( vso.vNor );
// Shade (Ambient + etc.)
o.Diffuse = float4( Diffuse( Normal ), 1.0 );
// copy the input texture coordinate through
o.Tex0 = i.Tex0.xy;
return o;
}
int CurNumBones = 2;
VertexShader vsArray20[ 4 ] = { compile vs_2_0 VShade( 1 ),
compile vs_2_0 VShade( 2 ),
compile vs_2_0 VShade( 3 ),
compile vs_2_0 VShade( 4 ) };
VertexShader vsArray11[ 4 ] = { compile vs_1_1 VShade( 1 ),
compile vs_1_1 VShade( 2 ),
compile vs_1_1 VShade( 3 ),
compile vs_1_1 VShade( 4 ) };
VertexShader vsArray2s[ 4 ] = { compile vs_2_sw VShade( 1 ),
compile vs_2_sw VShade( 2 ),
compile vs_2_sw VShade( 3 ),
compile vs_2_sw VShade( 4 ) };
//////////////////////////////////////
// Techniques specs follow
//////////////////////////////////////
technique t0
{
pass p0
{
VertexShader = ( vsArray20[ CurNumBones ] );
PixelShader = NULL;
}
}
technique t1
{
pass p0
{
VertexShader = ( vsArray11[ CurNumBones ] );
PixelShader = NULL;
}
}
technique t2
{
pass p0
{
VertexShader = ( vsArray2s[ CurNumBones ] );
PixelShader = NULL;
}
}